import 'package:flutter/material.dart';



// 步骤条
class StepperCompont extends StatefulWidget {
  final int currentStep;  // 当前第几步
  final List children;   // 列表组
  final dynamic onClick;        // 点击事件



  StepperCompont({
    Key key,
    this.currentStep=0,
    this.children,
    this.onClick


  }) : super(key: key);  

  @override
  _StepperCompontState createState() => new _StepperCompontState();
}


class _StepperCompontState extends State<StepperCompont> {


  // // 遍历 步骤条  
  // Widget _bodyInit() {

  //   if( widget.children!=null && widget.children.length>=1 ){
  //     List _child=widget.children;   // 子级
  //     // int _step=(widget.currentStep+1>=_child.length)?_child.length:widget.currentStep;  // 节点
  //     int _step=widget.currentStep-1;  // 节点
      
  //     List<Step> _list = [];

  //     // Widget content; 
  //     for(var i = 0; i < _child.length; i++){
  //       _list.add(
  //         Step(
  //           title: Container(
  //             width: 260,
  //             child: Row(
  //               children: <Widget>[
  //                 Expanded(
  //                   child:  Text(
  //                     _child[i]["title"]!=null?_child[i]["title"]:'',
  //                     // overflow: TextOverflow.visible,
  //                   )
  //                 )
  //               ],
  //             )
  //           ),
  //           subtitle: Container(
  //             width: 260,
  //             child: Row(
  //               children: <Widget>[
  //                 Expanded(
  //                   child: Text(
  //                     _child[i]["content"]!=null?_child[i]["content"]:'',
  //                     // overflow: TextOverflow.visible,
  //                   )
  //                 )
  //               ],
  //             )
  //           ),
  //           content: Text(""),
  //           // state: StepState.error
  //           isActive: (i<_step)?true:false
  //         )
  //       );
  //     }

  //     return Stepper(
  //       currentStep: _step,
  //       physics: ClampingScrollPhysics(),
  //       // type: StepperType.horizontal,
  //       steps:_list,     
  //       controlsBuilder: (BuildContext context,{VoidCallback onStepContinue, VoidCallback onStepCancel}){
  //         return Container();
  //       },
  //       onStepTapped: (index) {
  //         if( widget.onClick!=null ){
  //           widget.onClick(index);
  //         }
  //         // print("jins dsd");
  //       },
  //       onStepCancel: () {
  //         // print("You are clicking the cancel button.");
  //       },
  //       onStepContinue: () {
  //         // print("You are clicking the continue button.");
  //       },
  //     );
  //   }


  //   return null;
  // }

  @override
  Widget build(BuildContext context) {

    return  Container(
      child: Stepper(
        // currentStep:widget.currentStep,
        // currentStep:0,
        physics: ClampingScrollPhysics(),
        // type: StepperType.horizontal,
        steps: ( (widget.children.length)==0?[{}]:widget.children ).asMap().keys.map((i) => Step(
          state: StepState.disabled,
          title: Container(
            width: 260,
            child: Row(
              children: <Widget>[
                // Container(
                //   child: (i==widget.currentStep) ? Icon(Icons.done,color: Colors.blue):null,
                // ),
                Expanded(
                  child:  Text(
                    (widget.children.length!=0 && widget.children[i]["title"]!=null)?widget.children[i]["title"]:'',
                    // style: TextStyle(
                    //   color: (i==widget.currentStep) ? Colors.blue : Colors.black
                    // )
                    
                    // overflow: TextOverflow.visible,
                  )
                )
              ],
            )
          ),
          subtitle: Container(
            width: 260,
            child: Row(
              children: <Widget>[
                Expanded(
                  child: Text(
                    ( widget.children.length!=0 && widget.children[i]["content"]!=null)?widget.children[i]["content"]:'',
                    // style: TextStyle(
                    //   color: (i==widget.currentStep) ? Colors.blue : Colors.black
                    // )
                    // overflow: TextOverflow.visible,
                  )
                )
              ],
            )
          ),
          content: Text(""),
          // state: StepState.error
          // isActive:false
          // isActive: ( (widget.children.length>=2) && (i<widget.children.length-1))?true:false
          isActive: (i==0) ?true:false
        
        )).toList(),
        controlsBuilder: (BuildContext context,{VoidCallback onStepContinue, VoidCallback onStepCancel}){
          return Container();
        },
        onStepTapped: (index) {
          if( widget.onClick!=null ){
            widget.onClick(index);
          }
          // print("jins dsd");
        },
        onStepCancel: () {
          // print("You are clicking the cancel button.");
        },
        onStepContinue: () {
          // print("You are clicking the continue button.");
        },
      )
    );
  }

}